// store.js
import { reactive, watch } from 'vue';

const store = reactive({
    darkMode: false,
    headerActive: 0,
    leftSideActive: 0,
    rightSideActive: 0,
    user: {
        name: 'John Doe',
        age: 30
    },
    // 方法用于从 localStorage 初始化状态
    initialize() {
        const savedState = localStorage.getItem('appState');
        if (savedState) {
            Object.assign(this, JSON.parse(savedState));
        }
    },
    // 方法用于保存状态到 localStorage
    saveState() {
        localStorage.setItem('appState', JSON.stringify(this));
    }
});

// 初始化状态
store.initialize();

// 监听状态变化并保存到 localStorage
watch(store, () => {
    console.log('State changed:', store);
    store.saveState();
}, { deep: true });

export default store;